package org.smile.db.handler;

import org.smile.db.result.QueryResult;

import java.sql.SQLException;

public class OneNamedFieldRowHandler extends RowHandler{

    protected String fieldName;

    public OneNamedFieldRowHandler(String fieldName){
        this.fieldName=fieldName;
    }

    public OneNamedFieldRowHandler(String fieldName,Class resultClass){
        this.fieldName=fieldName;
        this.resultClass=resultClass;
    }

    @Override
    public <E> E handle(QueryResult rs) throws SQLException {
        if(this.resultClass==null){
            return (E)rs.getObject(fieldName);
        }
        return (E)rs.getObject(fieldName,resultClass);
    }
}
